package com.tb.controller;

import com.tb.model.Topic;
import com.tb.service.TopicService;
import com.tb.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @description: 板块相关
 * @author: wangguichun
 * @create: 2018-04-14 12:44
 **/

@Controller
@RequestMapping("topic")
public class TopicController {

    @Autowired
    private TopicService topicService;


    //获取板块列表
    @RequestMapping("topicList")
    @ResponseBody
    public Response getTopicList(){
        Response response = new Response();
        List<Topic> topicList = topicService.getTopicList();
        response.setData(topicList);
        return response;
    }

    //板块页
    @RequestMapping({"/","index"})
    public String index(Model model){
        List<Topic> allTopic = topicService.getTopicList();
        List<Topic> hotTopics = topicService.getHotTopics();
        model.addAttribute("allTopic",allTopic);
        model.addAttribute("hotTopics",hotTopics);
        return "topic";
    }



}
